var member_id  = ws = '';
document.addEventListener('plusready',function(){
	ws = plus.webview.currentWebview();
	member_id = plus.storage.getItem('id');
	console.log(apiRoot + "?act=member_order&op=order_list"+member_id);
	$.ajax({ 
		type:"post",
		url:apiRoot + "?act=member_order&op=personal_flea",
		data:{member_id:member_id},
		dataType:'json', 
		success:function(data){
			console.log(JSON.stringify(data));
			if(data.code == 200){
				var html1 = '';  
				var html2 = '';
				var html3 = '';
				if(data.datas.my_flea.length > 0){
					$.each(data.datas.my_flea, function(key,val) {
						html1 += '<ul class="mui-table-view">'+
									'<li class="mui-table-view-cell">'+
										'<img class="mui-media-object mui-pull-left flea_detaile" data-goods_id="'+ val.goods_id +'" data-store_id="'+ val.store_id +'" data-type="flea" src="'+ pics + val.store_id + '/' + val.goods_image +'">'+
										'<div class="mui-media-body">'+
											'<div class="mui-ellipsis-2">'+ val.goods_name +'</div>'+
											'<h5>'+
												'<span><map class="mui-h5 red">￥</map>'+ val.goods_price +'</span>'+
												'<span class="flea_del" data-goods_id="'+ val.goods_id +'" data-type="goods">删除</span>'+							
											'</h5>'+
										'</div>'+
									'</li>'+
								'</ul>';
					})
					
				}else{
					html1 += '<div class="flea">你还没有已发布跳蚤商品！</div>';
				}
				if(data.datas.my_sellout_flea.length > 0){
					$.each(data.datas.my_sellout_flea, function(key,val) {
						html2 = '<ul class="mui-table-view">'+
									'<li class="mui-table-view-cell">'+
										'<img class="mui-media-object mui-pull-left flea_detaile" data-goods_id="'+ val.goods_id +'" data-store_id="'+ val.store_id +'" data-type="flea" src="'+ pics + val.store_id + '/' + val.goods_image +'">'+
										'<div class="mui-media-body">'+
											'<div class="mui-ellipsis-2">'+ val.goods_name +'</div>'+
											'<h5>'+
												'<span><map class="mui-h5 red">￥</map>'+ val.goods_price +'</span>'+
												'<span class="flea_del" data-goods_id="'+ val.goods_id +'" data-type="goods">删除</span>'+							
											'</h5>'+
										'</div>'+
									'</li>'+
								'</ul>';
					})
					
				}else{
					html2 += '<div class="flea">你还没有已卖出的跳蚤商品！</div>';
				}
				if(data.datas.my_purchase_flea.length > 0){
					$.each(data.datas.my_purchase_flea, function(key,val) {
						html3 += '<ul class="mui-table-view">'+
									'<li class="mui-table-view-cell">'+
										'<img class="mui-media-object mui-pull-left flea_detaile" data-goods_id="'+ val.my_purchase_flea.goods_id +'" data-store_id="'+ val.my_purchase_flea.store_id +'" data-type="purchase" src="'+ pics + val.my_purchase_flea.store_id + '/' + val.my_purchase_flea.goods_image +'">'+
										'<div class="mui-media-body">'+
											'<div class="mui-ellipsis-2">'+ val.my_purchase_flea.goods_name +'</div>'+
											'<h5>'+
												'<span><map class="mui-h5 red">￥</map>'+ val.my_purchase_flea.goods_price +'</span>'+
												'<span class="flea_del" data-goods_id="'+ val.my_purchase_flea.goods_id +'" data-type="order">删除</span>'+
											'</h5>'+
										'</div>'+
									'</li>'+
								'</ul>';
					})
					
				}else{
					html3 += '<div class="flea">当前你还没有已购买的跳蚤商品！</div>';
				}
				$('#item1mobile .mui-scroll').html(html1);
				$('#item2mobile .mui-scroll').html(html2);
				$('#item3mobile .mui-scroll').html(html3);
			}else{
				toast(data.datas.error);
			}
			//删除订单
			$('.flea_del').on('click',function(){
				var _this = $(this);
				var goods_id = _this.attr('data-goods_id');       //商品id
				var goodstype = _this.attr('data-type'); 
				console.log(goods_id+'---'+goodstype);
				$.ajax({
					type:"post",
					url:apiRoot + "?act=member_order&op=goods_order",
					data:{
						member_id:member_id,
						goods_id:goods_id,
						goodstype:goodstype
					},
					dataType:'json',
					success:function(data){
						console.log(JSON.stringify(data));
						if(data.code == 200){
							toast('删除成功！');
							_this.parent().parent().parent().parent().remove();
						}else{
							toast(data.datas.error);
						}
					},
					error:function(e){
						error();
					}
				});
			})
			//订单详情
			$('.flea_detaile').unbind('tap');
			$('.flea_detaile').on('tap',function(){
				var _this = $(this); 
				var goodsid = _this.attr('data-goods_id');       //商品id
				var store_id = _this.attr('data-store_id');		//商家id
				var purchase = _this.attr('data-type');		//商家id
				console.log(goodsid+'--'+store_id+'--'+purchase);
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./Flea_details.html','Flea_details.html',{},{goods_id:goodsid,store_id:store_id,purchase:purchase});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
			
			
		},
		error:function(e){
			console.log(JSON.stringify(e));
			toast('连接失败！');
		}
	});
	
},false)